<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;
use think\model\concern\SoftDelete;

/**
 * @property bool $pay_type 支付类型:1=微信支付,2=支付宝支付,3=余额支付
 * @property bool $status 支付状态:1=待支付,2=待发货,3=待收货,4=待评价,5=完成,6=取消,7=申请售后,8=待退货,9=退货中,10=售后完成,11=售后拒绝,12=撤销售后
 * @property float $pay_amount 支付金额
 * @property float $supply_price 供货总价
 * @property int $address_id 地址
 * @property int $confirmtime 确认时间
 * @property int $deletetime
 * @property int $id
 * @property int $paytime 支付时间
 * @property int $returntime 退货时间
 * @property int $user_id 用户
 * @property string $createtime
 * @property string $express 快递公司
 * @property string $mark 订单备注
 * @property string $order_sn 订单编号
 * @property string $reason 售后拒绝原因
 * @property string $return_express 退货快递公司
 * @property string $return_waybill 退货单号
 * @property string $waybill 快递单号
 * @property string $pay_source 订单来源
 * @property-read \app\model\Address $address
 * @property-read \app\model\SuperOrdersAfter $after
 * @property-read \app\model\SuperOrdersDetail[] $detail
 * @property-read \app\model\User $user
 * @property-read mixed $status_text
 * @method static \think\db\Query onlyTrashed()
 * @method static \think\db\Query withTrashed()
 * @mixin \think\Model
 */
class SuperOrders extends Model
{
    use SoftDelete;
	protected $createTime = 'createtime';
	protected $deleteTime = 'deletetime';
	
	protected $append = [
		'status_text'
	];
	
	public function getStatusTextAttr($value, $data)
	{
		$value = $value ? $value : ($data['status'] ?? '');
		$list = ['1' => '待支付', '2' => '待发货', '3' => '待收货', '4' => '待评价', '5' => '完成', '6' => '取消', '7' => '申请售后', '8' => '待退货', '9' => '退货中', '10' => '售后完成', '11' => '售后拒绝', '12' => '撤销售后'];
		return $list[$value] ?? '';
	}
	
	function user()
	{
		return $this->belongsTo(User::class,'user_id');
	}
	
	function detail()
	{
		return $this->hasMany(SuperOrdersDetail::class,'order_id');
	}
	
	function address()
	{
		return $this->belongsTo(Address::class,'address_id');
	}
	
	function after()
	{
		return $this->hasOne(SuperOrdersAfter::class,'order_id');
	}
}
